package com.yanyeori.framework.core.util;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.yanyeori.framework.core.thread.NamedTransmittableThreadLocal;
import org.springframework.core.NamedInheritableThreadLocal;
import org.springframework.core.NamedThreadLocal;

/**
 * ThreadLocal工具
 *
 * @author chenkuan 2023/10/5
 */
public class ThreadLocalUtil {
    /**
     * 创建一个 ThreadLocal
     */
    public static <T> ThreadLocal<T> create() {
        return new ThreadLocal<>();
    }

    /**
     * 创建一个 NamedThreadLocal
     */
    public static <T> ThreadLocal<T> create(String name) {
        return new NamedThreadLocal<>(name);
    }

    /**
     * 创建一个 InheritableThreadLocal
     */
    public static <T> ThreadLocal<T> createInheritable() {
        return new InheritableThreadLocal<>();
    }

    /**
     * 创建一个 NamedInheritableThreadLocal
     */
    public static <T> ThreadLocal<T> createInheritable(String name) {
        return new NamedInheritableThreadLocal<>(name);
    }

    /**
     * 创建一个 TransmittableThreadLocal
     */
    public static <T> ThreadLocal<T> createTransmittable() {
        return new TransmittableThreadLocal<>();
    }

    /**
     * 创建一个 NamedTransmittableThreadLocal
     */
    public static <T> ThreadLocal<T> createTransmittable(String name) {
        return new NamedTransmittableThreadLocal<>(name);
    }
}
